package com.mystudy;

/**
 * 将HDFS上的/17124080120/test5.txt文件下载到本地
 */
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
/**
 * HDFS Download
 */
public class DownloadHDFSFile {
    public static void main(String[] args) throws Exception{
        Configuration conf = new Configuration();
        //配置NameNode地址
        URI uri = new URI("hdfs://192.168.30.130:8020");
        //指定用户名，获取FileSystem对象
        FileSystem fs = FileSystem.get(uri,conf,"hadoop");
        //HDFS File
        Path src =new Path("/17124080120/test5.txt");
        //local file
        Path dst = new Path("e:\\test5.txt");
        //Linux 下
        //fs.copyToLoclFile(false,src.dst);
        //Windows下
        fs.copyToLocalFile(false,src,dst,true);
        fs.close();
        System.out.println("Download Successfully!");
    }
}
